package com.accenture.adf.newcodington.module7.sample;

/**
 * Event Pass Try-it is about checking the number of tickets assigned ticket ID's
 * 
 * Topic: Try-it on error handling using assert
 * 
 * Instructions:
 * Create a public class named 'EventPass_TryIt1' with main method() and apply the following changes
 * 1. Declare an integer for number of children attending the event inside main() method
 * 2. On next line, declare an integer for number of adults attending the event
 * 3. On next line, declare an integer for number of tickets
 * 4. Initialize the following variables:
 * 		a. number of children
 * 		b. number of adults
 * 		c. number of tickets with the sum of number of children and number of adults
 * 5. Declare a single dimensional integer array for ticket ID's
 * 6. Initialize the array with number of tickets as the size
 * 7. Print 'Verifying tickets assigned with ticket ID's' message to the console
 * 8. Declare an integer for ticket ID and initialize it with zero
 * 9. Use for loop with noOfTickets as the boundary to populate the ticket ID array
 * 		a. Ticket ID can be generated by adding 1 to the loop index
 * 		b. Assign ticket id generated to the respective index in the array
 * 10. Declare an integer variable for the loop index and initialize with zero
 * 11. Loop through the array using a do..while loop with array size as the boundary
 * 		a. Verify the each value of the ticket id array as not equal to zero using assert statement
 * 		b. Print ticket ID value to console
 * 		c. If equal to zero, print 'Mismatch in issuance of ticket ID's' to the console as an assertion error
 * 		d. Otherwise, increase the loop index and verify all the values in the array
 * 		e. In case no assertion errors, print 'Ticket ID's are assigned to total number of tickets issued.' to the console after exiting the loop
 * 
 */


public class EventPass_TryIt {
	
	public static void main(String[] args){		
				
		int noOfChildren;
		int noOfAdults;
		int noOfTickets;
		int[] ticketID;		
				
		noOfChildren = 2;
		noOfAdults = 2;
		noOfTickets = noOfChildren + noOfAdults;
		
		ticketID = new int[noOfTickets];
		
		System.out.println("Verifying tickets assigned with ticket ID's");
		
		int passID = 0;
		//Generate ticket ID's 	and populate ticket ID array
		for(int i=0;i<noOfTickets;i++){ // modify 'noOfTickets' to 'noOfTickets-1' so the last
										// element of the array doesn't get assigned a passID
										// which will trigger the assertion exception
			passID = i + 1;
			ticketID[i] = passID;
		}		
		
		//Verify all the tickets issued assigned with ticket ID's
		int index = 0;
		do{
			assert (ticketID[index] != 0) : "Mismatch in issuance of ticket ID's";
			System.out.println("Ticket ID = " + ticketID[index]);
			index++;
		}while(index < ticketID.length);
		
		System.out.println("Ticket ID's are assigned to total number of tickets issued.");
	}	
}
